//
//  ActivityAPI.swift
//  GLUZSwift
//
//  Created by xyanl on 2025/3/14.
//  Copyright © 2025 考拉🐨. All rights reserved.
//

import Foundation
import Moya

enum ActivityAPI {
    case getPopup
}

extension ActivityAPI: TargetType {
    var baseURL: URL {
        return URL(string: SystemEnvManager.shared.phpUrl)!
    }
    
    var path: String {
        switch self {
        case .getPopup:
            return "/api/demo/alert_status"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .getPopup:
            return .get
        }
    }
    
    var task: Moya.Task {
        // 公共参数
        var params: [String: Any] = [:]
        switch self {
        default:
            break
        }
        if method == .get {
            // 在发起GET请求时，确保使用 URLEncoding.default 编码方式，这样参数会被正确添加到URL的查询字符串中，而不是作为请求体发送。
            return .requestParameters(parameters: params, encoding: URLEncoding.default)
        } else {
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        }
    }
    
    // 公共头部信息
    var headers: [String: String]? {
        var headers: [String: String] = [:]
        headers["token"] = UserProfile.token
        headers["client"] = "app"
        headers["Content-type"] = "application/json;charset=utf-8"
        headers["requestStartTime"] = String(CFAbsoluteTimeGetCurrent())
        return headers
    }
}
